<?php

use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;

?>

<style>
    .flex-count {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
</style>

<div class="page-header">
  <h1>图文消息列表 <small>图文消息关联二维码</small></h1>
</div>

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title">素材总数统计</h3>
    </div>
    <div class="panel-body">
        <ul class="nav nav-pills flex-count" role="tablist">
            <li>
                <button class="btn btn-primary">
                语音总数量 <span class="badge"><?= $counts['voice_count'] ?></span>
                </button>
            </li>
            <li>
                <button class="btn btn-primary">
                视频总数量 <span class="badge"><?= $counts['video_count'] ?></span>
                </button>
            </li>
            <li>
                <button class="btn btn-primary">
                图片总数量 <span class="badge"><?= $counts['image_count'] ?></span>
                </button>
            </li>
            <li>
                <button class="btn btn-primary">
                图文总数量 <span class="badge"><?= $counts['news_count'] ?></span>
                </button>
            </li>
        </ul>
    </div>
</div>

<div class="media">
    <div class="media-left media-middle">
        <img class="media-object" src="" alt="">
    </div>
    <div clas="media-body">
        <h4></h4>
    </div>
</div>


<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        [
            'attribute' => 'thumb_url',
            'label' => '缩略图',
            'format' => 'raw',
            'value' => function($data) {
                return Html::img($data['thumb_url'], ['class' => 'thumbnail', 'style' => 'width:64px;height:64px;']);
            }
        ],
        [
            'attribute' => 'title',
            'label' => '标题',
            'format' => 'raw',
            'value' => function($data) {
                return Html::a($data['title'], $data['url'], ['target' => '_blank']);
            }
        ],
        [
            'attribute' => 'author',
            'label' => '作者',
        ],
        [
            'attribute' => 'digest',
            'label' => '摘要',
        ],
        [
            'attribute' => 'media_id',
            'label' => 'media_id',
        ],
        [
            'attribute' => 'create_time',
            'label' => '创建时间',
            'value' => function($data) {
                return date('Y-m-d H:i:s', $data['create_time']);
            }
        ],
        [
            'attribute' => 'update_time',
            'label' => '更新时间',
            'value' => function($data) {
                return date('Y-m-d H:i:s', $data['update_time']);
            }
        ],
        [
            'class' => 'yii\grid\ActionColumn',
            'template' => '{match}',
            'buttons' => [
                'match' => function ($url, $data, $key) {
                    $url = Url::to(['qrcode/match', 'relation' => $data['media_id']]);
                    $options = [
                        'title' => '关联二维码',
                        'aria-label' => 'match',
                        'class' => 'match',
                    ];
                    return Html::a('<span class="glyphicon glyphicon-qrcode"></span>', $url, $options);
                },
            ],
            // // 'options' => ['width' => 75],
            // 'visibleButtons' => [
            //     'verification' => function ($model, $key, $index) {
            //         if ((Yii::$app->user->id == 2) && ($model->shop == 1) && ($model->status == 2)) {
            //             return true;
            //         } elseif ((Yii::$app->user->id == 3) && ($model->shop == 2) && ($model->status == 2)) {
            //             return true;
            //         } else {
            //             return false;
            //         }
            //     },
            // ],
        ],
    ],
]); ?>